package com.lh.web.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lh.common.entity.SysUserRoleEntity;
import com.lh.common.utils.MapUtils;
import com.lh.web.dao.SysUserRoleDao;
import com.lh.web.service.SysUserRoleService;
import org.springframework.stereotype.Service;

import java.util.List;



/**
 * 用户与角色对应关系
 *
 * @author Mark sunlightcs@gmail.com
 */
//@Service("sysUserRoleService")
@Service
public class SysUserRoleServiceImpl extends ServiceImpl<SysUserRoleDao, SysUserRoleEntity> implements SysUserRoleService {

	@Override
	public void saveOrUpdate(Long userId, Long roleId) {
		//先删除用户与角色关系
		this.removeByMap(new MapUtils().put("user_id", userId));

		//保存用户与角色关系
		SysUserRoleEntity sysUserRoleEntity = new SysUserRoleEntity();
		sysUserRoleEntity.setUserId(userId);
		sysUserRoleEntity.setRoleId(roleId);
		this.save(sysUserRoleEntity);
	}

	@Override
	public List<Long> queryRoleIdList(Long userId) {
		return baseMapper.queryRoleIdList(userId);
	}

	@Override
	public int deleteBatch(Long[] roleIds){
		return baseMapper.deleteBatch(roleIds);
	}
}
